home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 3.6 KB | 102 lines | [TEXT/MPS ] |
- #
- # File: ProcessTool Sample.vu
- #
- # Contents: ProcessTool example usages.
- #
- # Copyright © 1992 Apple Computer, Inc. All rights reserved.
- #
-
- Libraries "ProcessTool.vulib";
-
- script ProcessToolSample()
- begin
-
- (* Results returned by external tool services are in the form of a 2- or 3-item list:
- { errorCode, returnedValue, optionalErrorString }
- The errorCode will be zero if the call succeeded.
- So the success or failure of the call can be found in item 1 of the list,
- the returnedValue (whether a number or string or list itself) in item 2,
- and an optional error string in item 3.
- If the list does not include the error string, accessing item 3 will return undefined.
- The task ReturnErrorString below checks for the existence of the error string. *)
-
-
- m := ProcessTool( "Initialize", TRUE ); # Initialize the ProcessTool on the TARGET.
- # if m[1] <> 0 # If error during initialization,
- # begin
- # println "ProcessTool could not be initialized"; # print error
- # println "Error ", m[1], ". ", ReturnErrorString( m[3] );
- # exit; # & exit this script.
- # end;
-
- println "Getting list of current processes:";
- m := ProcessTool( "ProcessNamesList" ); # Get list of process names.
- if m[1] = 0 # If no error,
- begin
- processList := m[2]; # copy the returnedValue, the process list.
- println processList; # & print the processList.
- end;
- else
- println "Error ", m[1], " occurred. ", ReturnErrorString( m[3] ); # else print error.
-
- println;
-
- println "Getting name of front process:";
- m := ProcessTool("FrontProcessName" ); # Get front process name.
- if m[1] = 0 # If no error,
- println m[2]; # print the front process name.
- else
- println "Error ", m[1], " occurred. ", ReturnErrorString( m[3] ); # else print error.
-
- println;
-
- println "Getting partition size and free memory of all active processes:";
- for i := 1 to card processList # Loop through items of processList:
- begin
- m := ProcessTool( "PartitionSize", processList[i] ); # Get partition size
- if m[1] = 0
- println "Partition size of ", processList[i], " is ", m[2];
- else
- println "PartitionSize of ", processList[i], " error ", m[1], " occurred. ", ReturnErrorString( m[3] );
- m := ProcessTool( "FreeMem", processList[i] ); # Get free memory
- if m[1] = 0
- println "Free Memory for ", processList[i], " is ", m[2];
- else
- println "FreeMem of ", processList[i], " error ", m[1], " occurred. ", ReturnErrorString( m[3] );
- end;
-
- println;
-
- println "Read a single byte:";
- m := ProcessTool( "ReadByte", 16384 ); # (small address uses regular V.U. number)
- if m[1] = 0
- println "The byte stored at address 16384 is ", m[2];
- else
- println "ReadByte error ", m[1], " occurred. ", ReturnErrorString( m[3] );
-
- println;
-
- println "Read a block of bytes into a list:";
- m := ProcessTool( "ReadBlock", '65536', 10 ); # (large address uses quoted number string)
- if m[1] = 0
- println "The 10 bytes stored starting at address 65536 are in the list: ", m[2];
- else
- println "ReadBlock error ", m[1], " occurred. ", ReturnErrorString( m[3] );
-
- end;
-
-
-
- (* External tools return a list with an OPTIONAL error string in the 3rd position.
- If there is no optional error string, then accessing that item in the list (m[3])
- will return undefined. This task check the given entry. If it's undefined, then
- the task replaces it with the empty string. That simplifies error handling: If
- there IS an error string, it is printed. If there is NOT, nothing is printed. *)
-
- task ReturnErrorString( errorStringEntry )
- begin
- if IsUndefined( errorStringEntry )
- return "";
- else
- return errorStringEntry;
- end;